#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>
#include <maya/MDGMessage.h>
#include "ColladaExporter.h"

#ifdef WIN32
#define MLL_EXPORT __declspec(dllexport)
#else
#define MLL_EXPORT
#endif

// initializePlugin: called when the plug-in is loaded into Maya.
MStatus MLL_EXPORT initializePlugin(MObject obj)
{
	MStatus status;

	// Create a plug-in object.
#ifdef _DEBUG
	MFnPlugin plugin(obj, "Sebastien Pellizzari", PLUGIN_VERSION " (Debug)", "Any");
#else
	MFnPlugin plugin(obj, "Sebastien Pellizzari", PLUGIN_VERSION, "Any");
#endif

	// Register the exporter.
	status = plugin.registerFileTranslator(EXPORTER_NAME, "", ColladaExporter::creator, "MayaColladaExporterOptionsScript");
	if (status != MStatus::kSuccess)
	{
		status.perror("registerFileTranslator");
		MGlobal::displayError(MString("Unable to register MayaColladaExporter exporter: ") + status);
		return status;
	}

	// Load scripts.
	status = MGlobal::executeCommand("source MayaColladaExporter.mel");
	if (status != MStatus::kSuccess)
	{
		status.perror("executeCommand");
		MGlobal::displayError(MString("Unable to load MEL script MayaColladaExporter.mel: ") + status);
		return status;
	}

	// Okay.
	return MStatus::kSuccess;
}

// uninitializePlugin: called when the plug-in is unloaded from Maya.
MStatus MLL_EXPORT uninitializePlugin(MObject obj)
{
	MStatus status;

	// Get the plug-in object.
	MFnPlugin plugin(obj);

	// Unregister the exporter.
    status = plugin.deregisterFileTranslator(EXPORTER_NAME);
	if (status != MStatus::kSuccess)
	{
		status.perror("deregisterFileTranslator");
		MGlobal::displayError(MString("Unable to unregister MayaColladaExporter exporter: ") + status);
		return status;
	}

	// Okay.
    return MStatus::kSuccess;
}
